import Vue from 'vue'
import { sessionStore } from 'store/dist/store.legacy'
const state = {
  index: {},
  url: process.env.VUE_APP_linkIndex_url,
}

const mutations = {
  setIndex (state, param) {
    sessionStore.set('linkIndex', param.data)
    state.index = param.data
  }
}

const actions = {
  setIndex ({ state, commit }, param) {
    let list = state.index
    if (list.length == 0) {
      list = sessionStore.get('linkIndex') || {}
    }

    if (list.length == 0) {
      window.axios(state.url).then(ret => {
        commit('setIndex', { data: ret.data })
      })
    } else {
      commit('setIndex', { data: list })
    }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}